<?php
/**
* Copyright (c) 2002-2007 BioWare Corp.
* http://www.bigdaddymonitor.org
*
* This file is part of the BigDaddy Monitoring
* program. It is free software distributed under
* the terms of the BSD License. It is ditributed
* in the hopes that it will be useful, but
* WITHOUT ANY WARRANTY; without event the implied
* warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE.
*
* The BSD License is available from:
* http://www.opensource.org/licenses/bsd-license.php
**/
$aResult = $BigDaddyHistory->GetBooleanHistoryByTime($_REQUEST["ID"], $nStartTime, $sType, time(), true);


$aDowntime = array(1, 0,-1,-2,-3);
$aDowntimeString = array("Uptime", "Unscheduled Downtime","Scheduled Downtime","Disabled","No Data");

?>

<style>

.uptimedata th
{
	text-align: left;
	background-color: #efefef;
	font-size: 9pt;
	font-weight: bold;
}

.uptimedata td
{
	border-bottom: 1px solid #888;
	font-size: 8pt;
	text-align: left;
}

.uptimedata td.greyline
{
	background-color: #efefef;
}

</style>

<p style="font-size: 12pt;
		border-bottom: 1px solid #aaa;
		padding-bottom: 5px;"><b><?=$sTitle;?></b><br>
<span style="font-size: 10pt;">Monitoring Period: <b><?=get_time_str($aResult["monitoringstart"], 1);?></b> to <b><?=get_time_str($aResult["monitoringend"], 1);?></b></span></p>

<div id="my-timeline" style="height: 200px; border: 1px solid #aaa"></div>

<?

for ($j=0; $j<count($aDowntime); $j++)
{
    if (is_array($aResult["valuechange"][$aDowntime[$j]]))
    {
		?>
		<p style="color: #990000"><b><?=$aDowntimeString[$j];?></b></p>
		
		<table border="0" cellpadding="5" class="uptimedata">
		
		<thead>
		<th>Start</th>
		<th>End</th>
		<th>Time</th>
		</thead>
		
		<?
		$k=1;
        for ($i=0; $i<count($aResult["valuechange"][$aDowntime[$j]]); $i++)
        {
            if ($aResult["valuechange"][$aDowntime[$j]][$i]["start"]>0)
            {
				if ($k%2 == 0)
				{
					$sClass = " class = \"greyline\"";
				}
				else
				{
					$sClass = "";
				}
            ?>
			<tr>
				<td <?=$sClass;?>><?=get_time_str($aResult["valuechange"][$aDowntime[$j]][$i]["start"], 1);?></td>
				<td <?=$sClass;?>><?=get_time_str($aResult["valuechange"][$aDowntime[$j]][$i+1]["end"], 1);?></td>
				<td <?=$sClass;?>><?=convertTimeToHours($aResult["valuechange"][$aDowntime[$j]][$i+1]["end"]-$aResult["valuechange"][$aDowntime[$j]][$i]["start"]);?></td>
			</td>
			</tr>
			
            <?
				$k++;
            }
            $i=$i+1;
        }
		?>
		</table>
		<?
        
    }
}
?>
